package be.dioubs.sportTrack.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.TextView;
import be.dioubs.sportTrack.R;
import be.dioubs.sportTrack.common.Constant;
import be.dioubs.sportTrack.common.GlobalFormatter;

public class DialogTrackDetail extends Dialog{
	private String title;
	private String desccription;
	private String sport;
	private Long distanceNb;
	private String distanceUnit;
	private String time;
	private Long date;
	private String heartRateMoy;
	private String heartRateMax;
	private String fitnessLevel;
	
	public DialogTrackDetail(Context context, int theme) {
		super(context, theme);
	}

	public void setTitle(String title) {
		this.title = title;

		 TextView textView = (TextView) findViewById(R.id.title);	
		 textView.setText(title);
	}

	public String getTitle() {
		return title;
	}

	public void setDesccription(String desccription) {
		this.desccription = desccription;
		
		 TextView textView = (TextView) findViewById(R.id.description);	
		 textView.setText(desccription);
	}

	public String getDesccription() {
		return desccription;
	}

	public void setSport(String sport) {
		Drawable drawable;

		this.sport = sport;
		
		ImageView image = (ImageView) findViewById(R.id.image);
    	
        if(sport.equals(Constant.SPORT_RUN))
        	drawable = getContext().getResources().getDrawable(R.drawable.run);
        else if(sport.equals(Constant.SPORT_BIKE))
        	drawable = getContext().getResources().getDrawable(R.drawable.bike);
        else
        	drawable = getContext().getResources().getDrawable(R.drawable.swim);
        
        image.setImageDrawable(drawable);
	}	
	
	public String getSport() {
		return sport;
	}
	
	public Long getDistanceNb() {
		return distanceNb;
	}

	public void setDistanceNb(Long distanceNb) {
		this.distanceNb = distanceNb;
		
		TextView textView = (TextView) findViewById(R.id.distance_nb);	
		textView.setText(distanceNb.toString());
	}

	public String getDistanceUnit() {
		return distanceUnit;
	}

	public void setDistanceUnit(String distanceUnit) {
		this.distanceUnit = distanceUnit;
		
		TextView textView = (TextView) findViewById(R.id.distance_unit);	
		textView.setText(distanceUnit);
	}

	public void setTime(String time) {
		this.time = time;
		
		 TextView textView = (TextView) findViewById(R.id.time);	
		 textView.setText(time);
	}	
	
	public String getTime() {
		return time;
	}	
	
	public void setDate(Long date) {
		this.date = date;
		
		TextView textView = (TextView) findViewById(R.id.date);	
		textView.setText(GlobalFormatter.date(date));
	}

	public Long getDate() {
		return date;
	}

	public void setHeartRateMoy(String heartRateMoy) {
		this.heartRateMoy = heartRateMoy;

		 TextView textView = (TextView) findViewById(R.id.heartRateMoy);	
		 textView.setText(heartRateMoy);
	}

	public String getHeartRateMoy() {
		return heartRateMoy;
	}

	public void setHeartRateMax(String heartRateMax) {
		this.heartRateMax = heartRateMax;
		
		 TextView textView = (TextView) findViewById(R.id.heartRateMax);	
		 textView.setText(heartRateMax);
	}

	public String getHeartRateMax() {
		return heartRateMax;
	}
	
	public void setFitnessLevel(String fitnessLevel) {
		this.fitnessLevel = fitnessLevel;

		 TextView textView = (TextView) findViewById(R.id.fitnessLevel);	
		 textView.setText(fitnessLevel);		
	}

	public String getFitnessLevel() {
		return fitnessLevel;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_track_detail);
		
		ImageView buttonClose = (ImageView)findViewById(R.id.button_close);
		//buttonClose.setOnClickListener(new OKListener());
		buttonClose.setOnTouchListener(onTouchListener);
	}

    // Listener for Touch events
    private OnTouchListener onTouchListener = new OnTouchListener() {
    	public boolean onTouch(View view, MotionEvent motion) {
			switch(motion.getAction()) {
				case MotionEvent.ACTION_DOWN:
					touchDown(view);
					break;
				case MotionEvent.ACTION_UP:
					touchUp(view);
					break;
			}

			return true;
    	}
    };	
	
    // When user touch the screen (before releasing his finger)
    private void touchDown(View view) {
    	Drawable clicked = getContext().getResources().getDrawable(R.drawable.repeat_clicked);
    	((ImageView)view).setImageDrawable(clicked);
    }
    
    // When user releases his finger from the screen
    private void touchUp(View view) {
    	Drawable clicked = getContext().getResources().getDrawable(R.drawable.repeat);
    	((ImageView)view).setImageDrawable(clicked);
    	DialogTrackDetail.this.dismiss();
    }  
}
